﻿
namespace SHomeWorkshop.LunarPresentation.Commands
{
    public partial class Command
    {
        public static void BaseTextMaskLeftBias()
        {
            if (Globals.selectedEditor == null) return;
            if (Globals.selectedEditor.SelectedExpression == null) return;

            if (Globals.selectedEditor.SelectedExpression is Expressions.BaseText == false) return;

            Expressions.BaseText bt = Globals.selectedEditor.SelectedExpression as Expressions.BaseText;

            if (bt.Mask != Expressions.BaseText.MaskType.LeftBias)
            {
                ModifingItem mi = new ModifingItem();
                Action act = new Action(bt.ExID, -1, bt.GetType().Name, "Mask", bt.Mask.ToString(),
                    Expressions.BaseText.MaskType.LeftBias.ToString());

                bt.Mask = Expressions.BaseText.MaskType.LeftBias;

                mi.Add(act);

                bt.Editor.Do(mi);
                bt.Editor.IsModified = true;
            }
            else
            {
                Command.BaseTextMaskNone();
            }
        }

        public static void BaseTextMaskRightBias()
        {
            if (Globals.selectedEditor == null) return;
            if (Globals.selectedEditor.SelectedExpression == null) return;

            if (Globals.selectedEditor.SelectedExpression is Expressions.BaseText == false) return;

            Expressions.BaseText bt = Globals.selectedEditor.SelectedExpression as Expressions.BaseText;
            if (bt.Mask != Expressions.BaseText.MaskType.RightBias)
            {
                ModifingItem mi = new ModifingItem();
                Action act = new Action(bt.ExID, -1, bt.GetType().Name, "Mask", bt.Mask.ToString(),
                    Expressions.BaseText.MaskType.RightBias.ToString());

                bt.Mask = Expressions.BaseText.MaskType.RightBias;

                mi.Add(act);

                bt.Editor.Do(mi);
                bt.Editor.IsModified = true;
            }
            else
            {
                Command.BaseTextMaskNone();
            }
        }

        public static void BaseTextMaskHLine()
        {
            if (Globals.selectedEditor == null) return;
            if (Globals.selectedEditor.SelectedExpression == null) return;

            if (Globals.selectedEditor.SelectedExpression is Expressions.BaseText == false) return;

            Expressions.BaseText bt = Globals.selectedEditor.SelectedExpression as Expressions.BaseText;
            if (bt.Mask != Expressions.BaseText.MaskType.RightBias)
            {
                ModifingItem mi = new ModifingItem();
                Action act = new Action(bt.ExID, -1, bt.GetType().Name, "Mask", bt.Mask.ToString(),
                    Expressions.BaseText.MaskType.HLine.ToString());

                bt.Mask = Expressions.BaseText.MaskType.HLine;

                mi.Add(act);

                bt.Editor.Do(mi);
                bt.Editor.IsModified = true;
            }
            else
            {
                Command.BaseTextMaskNone();
            }
        }

        public static void BaseTextMaskVLine()
        {
            if (Globals.selectedEditor == null) return;
            if (Globals.selectedEditor.SelectedExpression == null) return;

            if (Globals.selectedEditor.SelectedExpression is Expressions.BaseText == false) return;

            Expressions.BaseText bt = Globals.selectedEditor.SelectedExpression as Expressions.BaseText;
            if (bt.Mask != Expressions.BaseText.MaskType.RightBias)
            {
                ModifingItem mi = new ModifingItem();
                Action act = new Action(bt.ExID, -1, bt.GetType().Name, "Mask", bt.Mask.ToString(),
                    Expressions.BaseText.MaskType.VLine.ToString());

                bt.Mask = Expressions.BaseText.MaskType.VLine;

                mi.Add(act);

                bt.Editor.Do(mi);
                bt.Editor.IsModified = true;
            }
            else
            {
                Command.BaseTextMaskNone();
            }
        }

        public static void BaseTextMaskHVLine()
        {
            if (Globals.selectedEditor == null) return;
            if (Globals.selectedEditor.SelectedExpression == null) return;

            if (Globals.selectedEditor.SelectedExpression is Expressions.BaseText == false) return;

            Expressions.BaseText bt = Globals.selectedEditor.SelectedExpression as Expressions.BaseText;
            if (bt.Mask != Expressions.BaseText.MaskType.RightBias)
            {
                ModifingItem mi = new ModifingItem();
                Action act = new Action(bt.ExID, -1, bt.GetType().Name, "Mask", bt.Mask.ToString(),
                    Expressions.BaseText.MaskType.HVLine.ToString());

                bt.Mask = Expressions.BaseText.MaskType.HVLine;

                mi.Add(act);

                bt.Editor.Do(mi);
                bt.Editor.IsModified = true;
            }
            else
            {
                Command.BaseTextMaskNone();
            }
        }

        public static void BaseTextMaskNone()
        {
            if (Globals.selectedEditor == null) return;
            if (Globals.selectedEditor.SelectedExpression == null) return;

            if (Globals.selectedEditor.SelectedExpression is Expressions.BaseText == false) return;

            Expressions.BaseText bt = Globals.selectedEditor.SelectedExpression as Expressions.BaseText;
            if (bt.Mask != Expressions.BaseText.MaskType.None)
            {
                ModifingItem mi = new ModifingItem();
                Action act = new Action(bt.ExID, -1, bt.GetType().Name, "Mask", bt.Mask.ToString(),
                    Expressions.BaseText.MaskType.None.ToString());

                bt.Mask = Expressions.BaseText.MaskType.None;

                mi.Add(act);

                bt.Editor.Do(mi);
                bt.Editor.IsModified = true;
            }
        }
    }
}
